package com.ruoyi.weixin.shop.controller;

import java.util.Arrays;
import java.util.List;

import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.weixin.shop.domain.vo.WxTabbarAddBo;
import com.ruoyi.weixin.shop.domain.vo.WxTabbarEditBo;
import com.ruoyi.weixin.shop.domain.vo.WxTabbarQueryBo;
import com.ruoyi.weixin.shop.domain.vo.WxTabbarVo;
import com.ruoyi.weixin.shop.service.IWxTabbarService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 底部导航Controller
 *
 * @author ruoyi
 * @date 2021-07-20
 */
@Api(value = "底部导航控制器", tags = {"底部导航管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wx/shop/wxtabbar")
public class WxTabbarController extends BaseController {

	private final IWxTabbarService iWxTabbarService;

	/**
	 * 查询底部导航列表
	 */
	@ApiOperation("查询底部导航列表")
	@PreAuthorize("@ss.hasPermi('system:tabbar:list')")
	@GetMapping("/list")
	public TableDataInfo<WxTabbarVo> list(@Validated WxTabbarQueryBo bo) {
		return iWxTabbarService.queryPageList(bo);
	}

	/**
	 * 导出底部导航列表
	 */
	@ApiOperation("导出底部导航列表")
	@PreAuthorize("@ss.hasPermi('system:tabbar:export')")
	@GetMapping("/export")
	public AjaxResult<WxTabbarVo> export(@Validated WxTabbarQueryBo bo) {
		List<WxTabbarVo> list = iWxTabbarService.queryList(bo);
		ExcelUtil<WxTabbarVo> util = new ExcelUtil<WxTabbarVo>(WxTabbarVo.class);
		return util.exportExcel(list, "底部导航");
	}

	/**
	 * 获取底部导航详细信息
	 */
	@ApiOperation("获取底部导航详细信息")
	@PreAuthorize("@ss.hasPermi('system:tabbar:query')")
	@GetMapping("/{id}")
	public AjaxResult<WxTabbarVo> getInfo(@NotNull(message = "主键不能为空")
										  @PathVariable("id") Long id) {
		return AjaxResult.success(iWxTabbarService.queryById(id));
	}

	/**
	 * 新增底部导航
	 */
	@ApiOperation("新增底部导航")
	@PreAuthorize("@ss.hasPermi('system:tabbar:add')")
	@PostMapping()
	public AjaxResult<Void> add(@Validated @RequestBody WxTabbarAddBo bo) {
		return toAjax(iWxTabbarService.insertByAddBo(bo) ? 1 : 0);
	}

	/**
	 * 修改底部导航
	 */
	@ApiOperation("修改底部导航")
	@PreAuthorize("@ss.hasPermi('system:tabbar:edit')")
	@PutMapping()
	public AjaxResult<Void> edit(@Validated @RequestBody WxTabbarEditBo bo) {
		return toAjax(iWxTabbarService.updateByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 删除底部导航
	 */
	@ApiOperation("删除底部导航")
	@PreAuthorize("@ss.hasPermi('system:tabbar:remove')")
	@DeleteMapping("/{ids}")
	public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
								   @PathVariable Long[] ids) {
		return toAjax(iWxTabbarService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
	}
}
